package br.com.skytef.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConnectionFactory {
	public static Connection getConnectionTomcat(boolean tomcat)
			throws Exception {

		InitialContext context = new InitialContext();
		DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/log_algorix_testes");

		try {
			return ds.getConnection();
		} catch (SQLException e) {
			throw new Exception(e.getMessage());
		}
	}

	public static Connection getConnections() {
		String url;
		String password;
		String dbName;
		String driver;
		String userName;

		try {

			Connection conn = null;
			dbName = "log_algorix_testes?allowMultiQueries=true";
				
			//### Servidor Dallas ###
			//password = "";
			//url = "jdbc:mysql://184.172.45.130:3306/";

			//### Servidor  ###
			password = "qwe123";
			url = "jdbc:mysql://192.168.0.70:3306/";
			driver = "com.mysql.jdbc.Driver";
			
			userName = "root";

			DriverManager.registerDriver(new com.mysql.jdbc.Driver());
			conn = DriverManager.getConnection(url + dbName, userName, password);

			return conn;

		} catch (SQLException e) {
			throw new RuntimeException(e);
		}

	}

	public static Connection getConnection() {
		return getConnections();
	}
}